extends Area2D

@export var speed: float = 1000
@onready var gpu_particles_2d: GPUParticles2D = $GPUParticles2D
#@onready var audio_stream_player_2d: AudioStreamPlayer = $AudioStreamPlayer2D

var all_delta: float
var velocity: Vector2 = Vector2.ZERO
var target_position: Vector2
var is_ready: bool = false


func _ready() -> void:
	var timer := Timer.new()
	timer.wait_time = 5
	timer.autostart = true
	add_child(timer)
	timer.timeout.connect(queue_free)
	body_entered.connect(_on_body_entered)
	

func _physics_process(delta: float) -> void :
	global_position += velocity * speed * delta




func set_velocity(_position: Vector2, current_speed:float = speed) -> void :
	target_position = _position
	speed = current_speed
	velocity = (target_position - global_position).normalized()






func _on_body_entered(_body: Node2D) -> void :
	_body.die()
	queue_free()
